Reduce use of madvise DODUMP/DONTDUMP#95643
Conversation
a74nh
commented
Dec 5, 2023
- When reserving memory, do not mark as DONTDUMP if the memory will be committed immediately afterwards.
- When committing memory that has only just been allocated, do not mark as DODUMP (as this is the default).
- When resetting memory, only call madvise once.
* When reserving memory, do not mark as DONTDUMP if the memory will be committed immediately afterwards. * When committing memory that has only just been allocated, do not mark as DODUMP (as this is the default). * When resetting memory, only call madvise once.
|
As discussed in #87173 |
|
cc: @Maoni0 |
fafb0f7 to
ab47f4e
Compare
| // Do not include reset memory in coredump. | ||
| madvise(address, size, MADV_DONTDUMP); | ||
| // In case the MADV_FREE is not supported, use MADV_DONTNEED | ||
| st = posix_madvise(address, size, MADV_DONTNEED); |
There was a problem hiding this comment.
We are missing the MADV_DONTDUMP for this case.
There was a problem hiding this comment.
Annoyingly MADV_DONTDUMP isn't supported for posix_madvise(), so we need to call madvise() again.
There was a problem hiding this comment.
i've just found an interesting comment in the posix_madvise doc:
In glibc, this function is implemented using madvise(2).
However, since glibc 2.6, POSIX_MADV_DONTNEED is treated as a no-
op, because the corresponding madvise(2) value, MADV_DONTNEED,
has destructive semantics.
Interestingly, we are passing MADV_DONTNEED instead of POSIX_MADV_DONTNEED to the posix_madvise. I don't know what is the actual result of calling posix_madvise in such case.
There was a problem hiding this comment.
Interestingly, we are passing
MADV_DONTNEEDinstead ofPOSIX_MADV_DONTNEEDto theposix_madvise. I don't know what is the actual result of callingposix_madvisein such case.
These are both 4. I've updated to POSIX_MADV_DONTNEED to make it explicit.
i've just found an interesting comment in the posix_madvise doc:
In glibc, this function is implemented using madvise(2).
However, since glibc 2.6, POSIX_MADV_DONTNEED is treated as a no-
op, because the corresponding madvise(2) value, MADV_DONTNEED,
has destructive semantics.
Glibc 2.6 was introduced in 2007. Ubuntu 22.04 has Glibc 2.35.
Given that and all the ifdef protections, it feels very unlikely that calling posix_madvise() after a failing madvise() would ever do anything.
I've updated so that posix_madvise() is only called if MADV_DONTDUMP does not exist.
|
Quick ping on this. Everything should be fixed now. |
janvorli
left a comment
There was a problem hiding this comment.
I have one last comment, otherwise it looks good.